Skip to content

Introduce typed asset storage and embed example resources - #80

Merged
Milky2018 merged 3 commits into
mainfrom
milky/embed-example-assets
Nov 13, 2026
Merged

Milky2018 merged 3 commits into
mainfrom
milky/embed-example-assets

Conversation

@Milky2018

@Milky2018 Milky2018 commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

Path-only resource loading makes embedded game assets depend on filename lookup adapters. This PR separates resource construction, storage, and identity: construct an Image, Audio, or Font from encoded bytes, then register it with Assets[T] to obtain a Handle[T].

let image = @asset.images.add(
  @asset.Image::from_bytes(@embedded_assets.assets.cards.a_c_png),
)

Changes

  • Introduce independent typed collections with reservation, insertion, replacement, and removal. Handle identity and hashing are independent of resource contents; foreign collection operations are rejected and removed handles cannot be resurrected. Handles provide read-only entry access and one-shot invalidation notifications for backend caches.
  • Use the same image values and handles for Sprite, UI, autotile visuals, cubemaps, and 3D material textures. Remove the separate 3D image registry and image synchronization records. ImageHandle, AudioHandle, and FontHandle are typed handle aliases; the former integer constructors and 3D image registration APIs are removed.
  • Preserve path loaders as compositions over the same default collections. Separate encoded-data availability from backend preparation states (Unprepared, Preparing, Ready, Failed). Registration performs no file IO or media decoding.
  • Prepare WebGPU media through owned Blob URLs and parse font bytes directly. Cache by resource identity, cancel stale image/font work, invalidate prepared objects on collection updates, and retain audio sources while playback instances still use them. Replacing path IO does not interrupt registered audio.
  • Embed example assets with moonbit-community/embed@0.1.3 through dev_build. The games reference generated resource fields directly and reuse handles; remove handwritten path catalogues and fake filesystem readers. Update diagnostics and atlas overlays to support resources without filenames.
  • Let Tiled world patterns discover sorted, deduplicated direct children from the optional asset-reader path catalogue. Remove moonbitlang/x, the browser preloader, and asset manifests. Pages copies only the bundles and static page files, including the arrow-key instruction image.
  • Reuse existing browser bindings without adding handwritten JS FFI. Remove the font-byte fetch bridge. Use FixedArray through the existing JS interop API for method calls, with tests for the current js-ffi array ABI and null handling.

Directory inputs still require explicit file dependency lists with the current Moon toolchain; listing a directory alone misses content changes during incremental builds. Generated embedded data is ignored by Git and rebuilt by ordinary Moon commands.

Validation

  • moon check --target all --deny-warn --warn-list +73
  • moon test --deny-warn --warn-list +73: 446 Wasm and 89 JS tests passed.
  • python3 -m unittest discover -s tests: 30 existing release and ECS API tests passed.
  • moon fmt --check, moon info --target all, pinned codegen freshness checks, and git diff --check.
  • moon build --target js --release --deny-warn --warn-list +73; verified the Pages copy inputs.
  • All three examples ran in Chromium with game asset network requests blocked: textures and fonts loaded without page errors, and Pixel Adventure jump audio played from a Blob source. The HTML instruction image remains static.
  • An external MoonBit browser consumer verified custom collection handles across 2D/UI/3D bindings, preparation failures, replacement/removal, texture retirement, font callback races, and audio Blob retention until playback stops.

@Milky2018 Milky2018 changed the title Embed example game assets and replace Tiled filesystem discovery Introduce typed asset storage and embed example resources Nov 12, 2026
@Milky2018
Milky2018 merged commit 1d97d32 into main Nov 13, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant